package com.gdit.zax.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gdit.zax.Constant;
import com.gdit.zax.dao.VideoDao;
import com.gdit.zax.entitys.VideoALL;
import com.gdit.zax.factory.DAOFactory;
import com.gdit.zax.utils.DBUtil;
import com.gdit.zax.utils.MD5;
import com.gdit.zax.utils.O;
import com.gdit.zax.utils.TextUtil;

public class GetVideoInfo extends HttpServlet {
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		int videoid = TextUtil.String2int(request.getParameter("videoid"), -1) ;
		
		//检测参数
		if (videoid<0) {
			O.printFail(response, 1, "请检查videoid参数!");
			return;
		}
		
		//检测连接、用户
		Connection conn = DBUtil.getConnection();
		if (conn==null) {
			O.printFail(response, 1000, "数据库连接失败!");
			return;
		}
		
		//开始
		DAOFactory dao = DAOFactory.init(conn, request, response);
		VideoDao vdao = dao.getVideoDao();
		
		VideoALL video = vdao.getVideoAllInfo(videoid);
		if (video==null) {
			O.printFail(response, 1, "该视频信息部完整，请联系管理员!");
			return;
		}
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("course", video.getT_course_name());
		map.put("section", video.getT_section_name());
		map.put("name", video.getT_video_name());
		map.put("anthor", video.getT_user_nick()	);
		map.put("time", video.getT_video_addtime());
		
		map.put("url", Constant.WEBRoot +video.getT_video_url());
		
		map.put("pic", Constant.WEBRoot +video.getT_video_pic());
		map.put("score", 0);
		
		map.put("commentsum", video.getT_video_commentsum());
		map.put("seesum", video.getT_video_seesum());
		
		map.put("downsum", video.getT_video_seesum());
		map.put("Introduction", video.getT_video_introduction());
		
		O.printSuccess(response, map);
		
	}

}
